﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DTO;
using System.Data;
using MyHotel_Common;
using System.Data.SqlClient;
namespace MyHotel_DAO
{
    public class MenuDAO : DAO
    {
        protected override object createObjectFromDatarow(DataRow row)
        {
            Menu mn = new Menu();
            mn.MaMenu = Int32.Parse(row["MaMenu"].ToString());
            mn.TenMenu = row["TenMenu"].ToString();
            mn.GiatriMenu = row["GiatriMenu"].ToString();
            return mn;
        }
        public List<Menu> getList()
        {

           
            string nameProc = "USP_LAY_DANH_SACH_Menu";
            DataTable dt = DataProvider.executeStoreProcedureQuery(nameProc, null);

            return getListFromDataTable<Menu>(dt); 
           
        }
        public bool themMenu(Menu menu)
        {
            string nameProc = "SP_THEMMENU";
            SqlParameter[] para = new SqlParameter[2];
            para[0] = new SqlParameter("@TenMenu", menu.TenMenu);
           
            para[1] = new SqlParameter("@GiatriMenu", menu.GiatriMenu);
            

            return (DataProvider.executeStoreProcedureNonQuery(nameProc, para) == 1);
        }

        public List<Menu> getMenuByMaNV(int manv)
        {
            string nameProc = "SP_GETMENU_BY_MANV";
            SqlParameter para = new SqlParameter("@MANV", manv);
            DataTable dt = DataProvider.executeStoreProcedureQuery(nameProc, para);

            return getListFromDataTable<Menu>(dt);
        }

        public List<Menu> getMenuByMaNhomND(int maNND)
        {
            string nameProc = "SP_GETMENU_BY_MANND";
            SqlParameter para = new SqlParameter("@MANND", maNND);
            DataTable dt = DataProvider.executeStoreProcedureQuery(nameProc, para);

            return getListFromDataTable<Menu>(dt);
        }
    }
}
